﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Text;
using System.Windows.Forms;
using Common.Util;
using Tk.Soc.Share.Common.Helpers;

namespace pinduoduo
{
	// Token: 0x02000016 RID: 22
	public class HttpHelper
	{
		// Token: 0x060000D6 RID: 214 RVA: 0x0000D640 File Offset: 0x0000B840
		public static string HttpPost(string Url, string postDataStr, string bianma)
		{
			string result;
			try
			{
				HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(Url);
				httpWebRequest.Method = "POST";
				httpWebRequest.ContentType = "application/x-www-form-urlencoded";
				httpWebRequest.ContentLength = (long)Encoding.UTF8.GetByteCount(postDataStr);
				bool flag = postDataStr != null && postDataStr != "";
				if (flag)
				{
					UTF8Encoding utf8Encoding = new UTF8Encoding();
					byte[] bytes = utf8Encoding.GetBytes(postDataStr);
					httpWebRequest.ContentLength = (long)bytes.Length;
					using (Stream requestStream = httpWebRequest.GetRequestStream())
					{
						requestStream.Write(bytes, 0, bytes.Length);
					}
				}
				HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
				Stream responseStream = httpWebResponse.GetResponseStream();
				StreamReader streamReader = new StreamReader(responseStream, Encoding.GetEncoding(bianma));
				string text = streamReader.ReadToEnd();
				streamReader.Close();
				responseStream.Close();
				result = text;
			}
			catch (Exception ex)
			{
				MessageBox.Show("网络不稳定，未加载到数据，请稍后重试");
				result = "网络不稳定，未加载到数据，请稍后重试";
			}
			return result;
		}

		// Token: 0x060000D7 RID: 215 RVA: 0x0000D758 File Offset: 0x0000B958
		public static string HttpPost(string Url, string postDataStr, string bianma, string cookie, string Referer_str, string host_str)
		{
			string result;
			try
			{
				string name = "";
				bool flag = !string.IsNullOrEmpty(bianma);
				if (flag)
				{
					name = bianma;
				}
				else
				{
					name = "utf-8";
				}
				HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(Url);
				httpWebRequest.Method = "POST";
				httpWebRequest.ContentType = "application/json";
				httpWebRequest.Accept = "application/json,text/javascript, */*; q=0.01";
				httpWebRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36";
				httpWebRequest.Referer = Referer_str;
				bool flag2 = !string.IsNullOrEmpty(host_str);
				if (flag2)
				{
					httpWebRequest.Host = host_str;
				}

				bool flag5 = !string.IsNullOrEmpty(cookie);
				if (flag5)
				{
					httpWebRequest.Headers.Add("Cookie", cookie);
				}

				httpWebRequest.KeepAlive = true;
				bool flag3 = postDataStr != null && postDataStr != "";
				if (flag3)
				{
					UTF8Encoding utf8Encoding = new UTF8Encoding();
					byte[] bytes = utf8Encoding.GetBytes(postDataStr);
					httpWebRequest.ContentLength = (long)bytes.Length;
					using (Stream requestStream = httpWebRequest.GetRequestStream())
					{
						requestStream.Write(bytes, 0, bytes.Length);
					}
				}
				HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
				Stream responseStream = httpWebResponse.GetResponseStream();
				StreamReader streamReader = new StreamReader(responseStream, Encoding.GetEncoding(name));
				string text = streamReader.ReadToEnd();
				streamReader.Close();
				responseStream.Close();
				result = text;
			}
			catch (Exception ex)
			{
				MessageBox.Show("网络不稳定，未加载到数据，请稍后重试");
				result = "网络不稳定，未加载到数据，请稍后重试";
			}
			return result;
		}

		// Token: 0x060000D8 RID: 216 RVA: 0x0000D8DC File Offset: 0x0000BADC
		public static string HttpPost(string Url, string postDataStr, string bianma, string cookie, string Referer_str, string host_str, Dictionary<string, string> dic_other,string daili=null)
		{
			string result;
			try
			{
				string name = "";
				bool flag = !string.IsNullOrEmpty(bianma);
				if (flag)
				{
					name = bianma;
				}
				else
				{
					name = "utf-8";
				}
				HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(Url);
				httpWebRequest.Method = "POST";
				httpWebRequest.ContentType = "application/json;charset=UTF-8";
				httpWebRequest.Accept = "*/*;zh-cn";
				httpWebRequest.UserAgent = "android Mozilla/5.0 (Linux; Android 6.1; OPPO R9tm Build/LMY47I; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/43.0.2357.121 Mobile Safari/537.36";
				httpWebRequest.Referer = Referer_str;

				if (!string.IsNullOrWhiteSpace(daili))
				{
					WebProxy proxy = RestClientUtil.CreateWebProxy(daili, true);
					httpWebRequest.Proxy = proxy;
				}

				bool flag2 = !string.IsNullOrEmpty(host_str);
				if (flag2)
				{
					httpWebRequest.Host = host_str;
				}
				bool flag3 = !string.IsNullOrEmpty(cookie);
				if (flag3)
				{
					httpWebRequest.Headers.Add("Cookie", cookie);
				}
				bool flag4 = dic_other.Count > 0;
				if (flag4)
				{
					foreach (string text in dic_other.Keys)
					{
						httpWebRequest.Headers.Add(text, dic_other[text]);
					}
				}
				httpWebRequest.KeepAlive = true;
				bool flag5 = postDataStr != null && postDataStr != "";
				if (flag5)
				{
					UTF8Encoding utf8Encoding = new UTF8Encoding();
					byte[] bytes = utf8Encoding.GetBytes(postDataStr);
					httpWebRequest.ContentLength = (long)bytes.Length;
					using (Stream requestStream = httpWebRequest.GetRequestStream())
					{
						requestStream.Write(bytes, 0, bytes.Length);
					}
				}
				HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
				Stream responseStream = httpWebResponse.GetResponseStream();
				StreamReader streamReader = new StreamReader(responseStream, Encoding.GetEncoding(name));
				string text2 = streamReader.ReadToEnd();
				streamReader.Close();
				responseStream.Close();
				result = text2;
			}
			catch (Exception ex) {
				LogHelper.Logger.Error("异常",ex);
			result = "";
				//result = "网络不稳定，未加载到数据，请稍后重试";
			}
			return result;
		}

		// Token: 0x060000D9 RID: 217 RVA: 0x0000DAF0 File Offset: 0x0000BCF0
		public static string HttpPost_Daili(string Url, string postDataStr, string bianma, string cookie, string Referer_str, string host_str)
		{
			string result;
			try
			{
				WebProxy proxy = RestClientUtil.CreateWebProxy("http://123.135.132.122:8118", true);
				string name = "";
				bool flag = !string.IsNullOrEmpty(bianma);
				if (flag)
				{
					name = bianma;
				}
				else
				{
					name = "utf-8";
				}
				HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(Url);
				httpWebRequest.Method = "POST";
				httpWebRequest.ContentType = "application/json";
				httpWebRequest.Accept = "application/json,text/javascript, */*; q=0.01";
				httpWebRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36";
				httpWebRequest.Proxy = proxy;
				httpWebRequest.Timeout = 60000;
				httpWebRequest.ReadWriteTimeout = 60000;
				httpWebRequest.Referer = Referer_str;
				bool flag2 = !string.IsNullOrEmpty(host_str);
				if (flag2)
				{
					httpWebRequest.Host = host_str;
				}
				httpWebRequest.KeepAlive = true;
				bool flag3 = postDataStr != null && postDataStr != "";
				if (flag3)
				{
					UTF8Encoding utf8Encoding = new UTF8Encoding();
					byte[] bytes = utf8Encoding.GetBytes(postDataStr);
					httpWebRequest.ContentLength = (long)bytes.Length;
					using (Stream requestStream = httpWebRequest.GetRequestStream())
					{
						requestStream.Write(bytes, 0, bytes.Length);
					}
				}
				HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
				Stream responseStream = httpWebResponse.GetResponseStream();
				StreamReader streamReader = new StreamReader(responseStream, Encoding.GetEncoding(name));
				string text = streamReader.ReadToEnd();
				streamReader.Close();
				responseStream.Close();
				result = text;
			}
			catch (Exception ex)
			{
				MessageBox.Show("IP受限，请换IP后继续采集");
				result = "IP受限，请换IP后继续采集";
			}
			return result;
		}

		public static string HttpGet_anzhou(string Url, string bianma, string cookie =null,string Referer_str=null,string host=null)
		{
			string result;
			try
			{
				Encoding encoding = Encoding.UTF8;
				bool flag = !string.IsNullOrEmpty(bianma) && bianma.ToLower() != "utf-8";
				if (flag)
				{
					encoding = Encoding.GetEncoding(bianma);
				}
				HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(Url);
				httpWebRequest.Method = "GET";
				httpWebRequest.ContentType = "text/html";
				httpWebRequest.UserAgent = "android Mozilla/5.0 (Linux; Android 8.1.0; vivo NEX A Build/OPM1.171019.019; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/62.0.3202.84 Mobile Safari/537.36  phh_android_version/3.23.0 phh_android_build/228842 phh_android_channel/qihu360";
				bool flag2 = !string.IsNullOrEmpty(cookie);
				if (flag2)
				{
					httpWebRequest.Headers.Add("Cookie", cookie);
				}
				bool flag3 = !string.IsNullOrEmpty(Referer_str);
				if (flag3)
				{
					httpWebRequest.Referer = Referer_str;
				}
				bool flag4 = !string.IsNullOrEmpty(host);
				if (flag4)
				{
					httpWebRequest.Host = host;
				}
				HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
				Stream responseStream = httpWebResponse.GetResponseStream();
				StreamReader streamReader = new StreamReader(responseStream, encoding);
				string text2 = streamReader.ReadToEnd();
				streamReader.Close();
				responseStream.Close();
				result = text2;
			}
			catch (Exception ex)
			{
				MessageBox.Show("网络不稳定，未加载到数据，请稍后重试");
				result = "";
			}
			return result;
		}


		// Token: 0x060000DA RID: 218 RVA: 0x0000DCA4 File Offset: 0x0000BEA4
		public static string HttpGet_anzhou(string Url, string postDataStr, string bianma, string cookie, string Referer_str, string host,Dictionary<string, string> dic_other=null)
		{
			string result;
			try
			{
				Encoding encoding = Encoding.UTF8;
				bool flag = !string.IsNullOrEmpty(bianma) && bianma.ToLower() != "utf-8";
				if (flag)
				{
					encoding = Encoding.GetEncoding(bianma);
				}
				string text = Url + ((postDataStr == "") ? "" : " ? ") + postDataStr;
				HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(Url + ((postDataStr == "") ? "" : "?") + postDataStr);
				httpWebRequest.Method = "GET";
				httpWebRequest.ContentType = "application/x-www-form-urlencoded;charset=utf-8";
				httpWebRequest.UserAgent = "android Mozilla/5.0 (Linux; Android 8.1.0; vivo NEX A Build/OPM1.171019.019; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/62.0.3202.84 Mobile Safari/537.36  phh_android_version/3.23.0 phh_android_build/228842 phh_android_channel/qihu360";
				bool flag2 = !string.IsNullOrEmpty(cookie);
				if (flag2)
				{
					httpWebRequest.Headers.Add("Cookie", cookie);
				}
				bool flag3 = !string.IsNullOrEmpty(Referer_str);
				if (flag3)
				{
					httpWebRequest.Referer = Referer_str;
				}
				bool flag4 = !string.IsNullOrEmpty(host);
				if (flag4)
				{
					httpWebRequest.Host = host;
				}

				bool flag5 = dic_other !=null&& dic_other.Count > 0;
				if (flag5)
				{
					foreach (string text1 in dic_other.Keys)
					{
						httpWebRequest.Headers.Add(text1, dic_other[text1]);
					}
				}
				HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
				Stream responseStream = httpWebResponse.GetResponseStream();
				StreamReader streamReader = new StreamReader(responseStream, encoding);
				string text2 = streamReader.ReadToEnd();
				streamReader.Close();
				responseStream.Close();
				result = text2;
			}
			catch (Exception ex)
			{
				//MessageBox.Show("网络不稳定，未加载到数据，请稍后重试");
				//result = "网络不稳定，未加载到数据，请稍后重试";
				result = "";
			}
			return result;
		}

		// Token: 0x060000DB RID: 219 RVA: 0x0000DE28 File Offset: 0x0000C028
		public static string HttpGet_daili(string Url, string postDataStr, string bianma, string cookie, string Referer_str)
		{
			string result;
			try
			{
				WebProxy proxy = RestClientUtil.CreateWebProxy("http://61.135.217.7:80", true);
				bool flag = !string.IsNullOrEmpty(bianma);
				string name;
				if (flag)
				{
					name = bianma;
				}
				else
				{
					name = "utf-8";
				}
				HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(Url + ((postDataStr == "") ? "" : "?") + postDataStr);
				httpWebRequest.Method = "GET";
				httpWebRequest.ContentType = "application/x-www-form-urlencoded;charset=UTF-8";
				httpWebRequest.Proxy = proxy;
				httpWebRequest.Timeout = 60000;
				httpWebRequest.ReadWriteTimeout = 60000;
				HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
				Stream responseStream = httpWebResponse.GetResponseStream();
				StreamReader streamReader = new StreamReader(responseStream, Encoding.GetEncoding(name));
				string text = streamReader.ReadToEnd();
				streamReader.Close();
				responseStream.Close();
				result = text;
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message + "|" + ex.StackTrace);
				result = "IP受限，请换IP后继续采集";
			}
			return result;
		}


		public static string HttpGet_daili(string Url, string daili, string cookie, string bianma)
		{
			string result;
			try
			{
				WebProxy proxy = RestClientUtil.CreateWebProxy(daili, true);
				bool flag = !string.IsNullOrEmpty(bianma);
				string name;
				if (flag)
				{
					name = bianma;
				}
				else
				{
					name = "utf-8";
				}
				HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(Url);
				httpWebRequest.Method = "GET";
				httpWebRequest.ContentType = "application/x-www-form-urlencoded;charset=UTF-8";
				httpWebRequest.UserAgent = "android Mozilla/5.0 (Linux; Android 8.1.0; vivo NEX A Build/OPM1.171019.019; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/62.0.3202.84 Mobile Safari/537.36  phh_android_version/3.23.0 phh_android_build/228842 phh_android_channel/qihu360";
				httpWebRequest.Proxy = proxy;
				httpWebRequest.Timeout = 60000;
				bool flag2 = !string.IsNullOrEmpty(cookie);
				if (flag2)
				{
					httpWebRequest.Headers.Add("Cookie", cookie);
				}
				httpWebRequest.ReadWriteTimeout = 60000;
				HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
				Stream responseStream = httpWebResponse.GetResponseStream();
				StreamReader streamReader = new StreamReader(responseStream, Encoding.GetEncoding(name));
				string text = streamReader.ReadToEnd();
				streamReader.Close();
				responseStream.Close();
				result = text;
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message + "|" + ex.StackTrace);
				result = "IP受限，请换IP后继续采集";
			}
			return result;
		}
	}
}
